package com.summer.log.center.model;


import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

public class LogDateSerialize extends JsonSerializer<Date> {

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (date==null){
            jsonGenerator.writeString("");
        }else {
            String format = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
            jsonGenerator.writeString(format);
        }

    }
}
